﻿//-----------------------------------------------------------------------
// <copyright file="URLMappers.cs" company="None">
//     Copyright None. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace ODataRegression.Framework.Core.Shared
{
    using System;
    using System.Xml;

    public static class URLMappers
    {
        private static XmlNodeList urlMappingActions;

        static URLMappers()
        {
            urlMappingActions = TestConfigReader.UrlMapperActions;
        }

        public static string ApplyConfigMappingActions(string url)
        {
            Type stringType = typeof(string);
            string find = string.Empty;
            string replace = string.Empty;

            if (!url.Contains("$metadata") && !url.Contains("$count") && !url.ToUpper().EndsWith(".SVC/") && !url.Contains("?"))
            {
               // url = url + "?";
            }

            foreach (XmlNode item in urlMappingActions)
            {
                url = StringHelpers.ExecuteStringFunctionViaReflection(item, url);
            }

            url = url.Replace("&&", "&");
            if (url.EndsWith("&"))
            {
                url = url.Substring(0, url.Length - 1);
            }

            return url;
        }
    }
}